import { IncomingMessage, ServerResponse } from 'http'

export interface MockOptions {
  // mock文件根目录，默认 src/mock
  root?: string
  // 是否打印debug信息
  debug?: boolean
  // 默认延时时间(ms)
  delay?: number
  // 自定义请求匹配规则
  requestMatch?: (req: IncomingMessage) => boolean
}

export interface MockContext {
  req: IncomingMessage
  res: ServerResponse
  options: Required<MockOptions>
  cleanPath: string
}

export const DEFAULT_OPTIONS: Required<MockOptions> = {
  root: 'src/mock',
  debug: false,
  delay: 0,
  requestMatch: req => req.url?.startsWith('/api') || false,
}
